# -*- coding: utf-8 -*-
# @Time : 2023/12/15 21:26
# @Author : Z
# @Email : 1473858993@qq.com
# @File : log.py
# @Project : apitwo
import logging
import os.path

from common.dir import log_dir


class LogUtil:
    def __init__(self, filename):
        # 获取一个logger对象
        loger = logging.getLogger()
        # 总日志级别
        loger.setLevel(logging.INFO)
        # 日志存放位置
        filepath = os.path.join(log_dir, filename)
        # 文件处理器hanler
        handler = logging.FileHandler(filepath, mode='a+', encoding='utf8')
        # 格式器
        fromatter = logging.Formatter('[%(levelname)s %(filename)s %(asctime)s]  ->%(message)s<-  %(lineno)d')
        # 设置日志输出格式
        handler.setFormatter(fromatter)
        # 添加handler
        loger.addHandler(handler)
